package leetcode.jianzhioffer;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-11-01 10:55
 **/
public class JianZhiOffer22 {

    public ListNode getKthFromEnd(ListNode head, int k) {
        //让fast节点先走k步,然后head节点和fake节点一起走
        ListNode fast = head;
        for (int i = 0; i < k; i++) {
            fast = fast.next;
        }
        while (fast != null) {
            fast = fast.next;
            head = head.next;
        }
        return head;
    }

}
